﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Web.DynamicData;
using System.Web.UI.WebControls;
using System.Collections;
//using NotAClue.ComponentModel.DataAnnotations;

namespace NotAClue.Web
{
    public static class EnumWebExtensionMethods
    {
        public static List<ListItem> GetEnumList(Type enumType)
        {
            var list = new List<ListItem>();
            foreach (DictionaryEntry entry in EnumExtensionMethods.GetEnumNamesAndValues(enumType))
            {
                list.Add(new ListItem((string)entry.Key, (string)entry.Value));
            }
            return list;
        }

        /// <summary>
        /// Fills the enum list control.
        /// </summary>
        /// <param name="list">The list.</param>
        /// <param name="enumType">Type of the enum.</param>
        /// <remarks></remarks>
        public static void FillEnumListControl(ListControl list, Type enumType)
        {
            foreach (var entry in enumType.EnumToDictionary().OrderBy(d=>d.Key))
            {
                list.Items.Add(new ListItem(entry.Key, entry.Value.ToString()));
            }
            //foreach (DictionaryEntry entry in EnumExtensionMethods.GetEnumNamesAndValues(enumType))
            //{
            //    list.Items.Add(new ListItem((string)entry.Key, (string)entry.Value));
            //}
        }
    }
}
